﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text.RegularExpressions;
using IHISCETeim.Web.AgentSys.SvrMgr;



namespace IHISCETeim.Web.MachineSys.UserModel.ExportExecl
{
    public partial class ExportUMacKeepList : UAgentMacKeepList
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }


        protected void DataBind()
        {

            DataTableCollection dtc = UMacKeepController.GetPagination(GetSqlWhere(), 1, 99999999, SQLSort, ref TotalCount);
            this.rpMenu.DataSource = dtc[0];
           this.rpMenu.DataBind();

            sumdt = dtc[1];

            ExportToExecl("代理商保养管制表", this.rpMenu);
        }

        protected object GetKeepValue2(object v)
        {
            try
            {
                decimal xx = Convert.ToDecimal(v);
                return xx;
            }
            catch
            {
                return "";
            }
        }

        protected object GetKeepValue(object x)
        {
            try
            {
               // return x;
                // return x.ToString();
                string sHtml = x.ToString();
                string oHtml = StringHelper.StripTags(sHtml,false);
                //return oHtml;
                if (!string.IsNullOrEmpty(oHtml))
                {//不为空
                    if (oHtml.Trim() == "保养")
                        return "";
                    return oHtml;
                    string[] shtmlarr = oHtml.Split(new char[] { '|' });

                    // oHtml = string.Format("<A  title='保养时间:{1}'>{0}</a>", shtmlarr[0], shtmlarr[1]);
                    // return oHtml;

                    decimal xx = Convert.ToDecimal(shtmlarr[0].Trim());
                    return xx;
                }
                else
                {
                    return "";
                }
            }
            catch
            {
                return "";
            }
        }

        protected string GetPer(object x1, object x2)
        {
            if (x1 is DBNull || x2 is DBNull)
                return "0";
            if (x2.ToString() == "0")
                return "0";

            return (Convert.ToDecimal(x1) / Convert.ToDecimal(x2) * 100).ToString("F0");
        }

        private List<UMacKeepDetailInfo> _detailList = null;
        private List<UMacKeepDetailInfo> DetailList
        {
            get
            {
                return _detailList;
            }
            set
            {
                _detailList = value;
            }
        }
        protected string GetUMacKeepDetail2(object SerialNumber, object KeepHours)
        {
            string _SerialNumber = SerialNumber.ToString();
            int _KeepHours = Convert.ToInt32(KeepHours);

            if (_detailList == null)
            {
                DetailList = UMacKeepController.UMacKeepDetail_GetBySerialNumber(_SerialNumber);
            }

            if (DetailList.Count(e => e.SerialNumber.ToUpper() == _SerialNumber.ToUpper()) <= 0)
            {
                DetailList = UMacKeepController.UMacKeepDetail_GetBySerialNumber(_SerialNumber.ToUpper());
            }

            UMacKeepDetailInfo _detail = DetailList.Find(e => e.KeepHours == _KeepHours);
            _detail = _detail == null ? new UMacKeepDetailInfo() : _detail;
            if (string.IsNullOrEmpty(_detail.SerialNumber))
            {
                return "";
            }
            else
            {
                return _detail.WorkTime.ToString() + " | " + _detail.KeepDate.ToString();
            }
            // List<UMacKeepDetailInfo> _detailList = UMacKeepController.UMacKeepDetail_GetBySerialNumber(_SerialNumber);

            // if()

        }

    }
}